package com.basic.library.bean

import android.os.Parcelable
import android.view.View
import kotlinx.parcelize.Parcelize

@Parcelize
data class UserInfo(
    val addTime: String? = null,  //添加时间
    val addUser: Int? = null,  //添加人
    var avatar: String? = null,  //头像
    val departmentId: String? = null,  //部门Id
    val departmentName: String? = null,  //部门名称
    val id: Int? = null,  //主键
    val isAdmin: Boolean? = null,  //是否管理员
    val marks: Boolean? = null,  //是否删除
    var mobile: String? = null,  //手机
    var password: String? = null,  //用户密码
    val pushId: String? = "",  //推送Id
    val remark: String? = null,  //备注
    val roles: List<Role>? = null,  //用户角色
    val rolesName: String? = null,  //用户所有角色名称
    val sex: String? = null,  //性别
    val sort: String? = null,  //排序
    val status: Boolean? = null,  //是否停用
    val superPassword: String? = null,  //超级密码
    val token: String? = "",  //登录令牌
    val trueName: String? = null,  //姓名
    val updateTime: String? = null,  //修改时间
    val updateUser: Int? = null,  //修改人
    val userName: String? = null,  //用户名
    var checked: Boolean = false,
    var isMain : Boolean = false,
) : Parcelable {
    val visibility: Int
        get() = if (departmentName.isNullOrEmpty()) View.GONE else View.VISIBLE

    fun hasPermission(name: String): Boolean {
        var hasPer = false
        roles?.run {
            if (size != 0) {
                forEach {
                    hasPer = hasPer || it.actionPower.split(",").contains(name)
                }
            }
        }
        return hasPer
    }
}

@Parcelize
data class Role(
    val name: String,
    val actionPower: String,
) : Parcelable
